package com.example.exception;

import com.example.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/*
 * 全局异常处理
 */
@ControllerAdvice("com.example.controller")
public class GlobalExceptionHandler {
  @ExceptionHandler(Exception.class)
  @ResponseBody
  public Result error(Exception e) {
    return Result.error();
  }

  @ExceptionHandler(CustomException.class)
  @ResponseBody
  public Result error(CustomException e) {
    return Result.error(e.getCode(), e.getMsg());
  }
}